﻿//Copyright (c) 2010, Andreas Grünwald
//All rights reserved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Slf;

namespace yaTDL.Extensions
{
    public static class DoubleExtensions
    {

        public static DateTime ToDateTime(this double value)
        {
            DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            origin = DateTime.SpecifyKind(origin, DateTimeKind.Utc);
            
            try
            {
                return DateTime.SpecifyKind(origin.AddSeconds(value).ToLocalTime(), DateTimeKind.Local);
            }
            catch (Exception)
            {
                LoggerService.GetLogger("DoubleExtensions").Error("Could not get DateTime from double value. Returning '01.01.0001 00:00:00' instead");
                return DateTime.Parse("01.01.0001 00:00:00");
            }
            
        }
    }
}
